using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

public class Demo : MonoBehaviour
{
    [DllImport("__Internal")]
    private static extern void ExecuteJsCmd(string json);


    public void Send(string data)
    {
        if (!string.IsNullOrEmpty(data))
        {
            Debug.Log($"ExecuteJsCmd:{data}");
#if !UNITY_EDITOR && UNITY_WEBGL
                ExecuteJsCmd(data);
#endif
        }
    }

    //js to c#
    //unityInstance.SendMessage('JAC', 'JsCallCSharp', JSON.stringify(obj));
    public void JsCallCSharp(string data)
    {
        Debug.Log($"unity.Receive:{data}");
        revStr = data;
    }

    private string inputStr="test";
    private string revStr;

    private void OnGUI()
    {
        GUILayout.Label(revStr, GUILayout.Width(120));
        inputStr = GUILayout.TextField(inputStr);
        if (GUILayout.Button("send") && !string.IsNullOrEmpty(inputStr))
        {
            Send(inputStr);
        }
    }
}